package com.vsd.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.annotation.LoginFilter;
import com.demo.bean.DataTable;
import com.demo.bean.Ret;
import com.demo.controller.CoreAdminController;
import com.demo.dialet.PaginationSupport;
import com.demo.util.JSONUtils;
import com.demo.validator.AdminLoginValidate;
import com.vsd.daoEx.model.ChangeLogEx;
import com.vsd.domain.ChangeLog;
import com.vsd.service.ChangeLogService;

@Controller
@RequestMapping("changeLog")
@LoginFilter(validateClz=AdminLoginValidate.class)
public class ChangeLogController extends CoreAdminController{
	@Autowired
	private ChangeLogService changeLogService;
 
	
	@RequestMapping("/list")
	@ResponseBody
	public String citylist(HttpSession session,@RequestParam("draw") Integer draw
			,@RequestParam("start") Integer start,@RequestParam("length") Integer length
			,@RequestParam("search[value]") String search,HttpServletRequest request){
		
		PaginationSupport.byPage(start/length+1, length);
		List<ChangeLogEx> list = changeLogService.selectExList(search);
		
		return JSONUtils.serialize(new DataTable(draw+1,PaginationSupport.getContext().getTotalCount(), list));
	}
	
	@RequestMapping("/check")
	@ResponseBody
	public String check(String id,Integer state){
		ChangeLog log = new ChangeLog();
		log.setId(id);
		log.setState(state);
		changeLogService.updateByPrimaryKeySelective(log);
		return JSONUtils.serialize(new Ret(0));
	}
	
}
